<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class article extends Model
{
    protected $table = 'article';
//    绑定主键
    protected $primaryKey = 'id';
//    定义禁止操作的时间
    public $timestamps = false;
//    设置允许写入的数据字段
    protected $fillable = ['*'];
//设置排除入库的字段
//    protected $guarded = [];


//模型关联 （一对一）

    public function author(){
        return $this -> hasOne('App\author','id','author_id');
    }
//一对多关联

    public function comment(){
        return $this -> hasMany('App\comment','article_id','id');
    }
//多对多
    public function keyWord(){
        return $this -> belongsToMany('App\keyWord','relation','article_id','key_id');
    }
}
